package com.example.springbootcontroller.EmployeeDao;

import com.example.springbootcontroller.bean.Employee;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//使用在Dao层实例化Bean
@Repository

public class EmployeeDao implements IEmployeeDao {
public EmployeeDao(){}
    private static Map<Integer,Employee> employees = new HashMap<>();
static {
    Employee e0=new Employee(0,"小明",20,"男");
    Employee e1=new Employee(1,"小红",19,"女");
    Employee e2=new Employee(2,"小黄",30,"男");
    Employee e3=new Employee(3,"小绿",60,"女");
    Employee e4=new Employee(4,"小兰",18,"女");
    employees.put(e0.getId(),e0);
    employees.put(e1.getId(),e1);
    employees.put(e2.getId(),e2);
    employees.put(e3.getId(),e3);
    employees.put(e4.getId(),e4);


}
    @Override
    public Employee getEmployeeByName(Integer id) {
        return employees.get(id);

    }

    @Override
    public List getEmployeeList() {
       List employeeList = new ArrayList(employees.values());
       return employeeList;
    }

    @Override
    public String addEmployee(Employee employee) {
        employees.put(employee.getId(),employee);
        return "succecss";
    }

    @Override
    public String updateEmployee(Integer id, Employee employee) {
        employees.get(id).setName(employee.getName());
        employees.get(id).setAge(employee.getAge());
        employees.get(id).setGender(employee.getGender());
        return "success";
    }

    @Override
    public String deleteEmployee(Integer id) {
        employees.remove(id);
        return "success";
    }
}
